import QtQuick 2.0
import "../delegate"
import org.qtproject.znews_qt 1.0

//tungvc
/*
    co ther thay the cac menuDelegate bang cac item khac dong thoi cung phai thay listmodel

*/
Rectangle {

    width: 400 * ApplicationInfo.ratio
    y:m_header.height;
    height: id_mainwindow.height - m_header.height
    color: "#D1DBBD"
    property real m_ratio: ApplicationInfo.ratio;

    property Component m_menuDelegate: MenuDelegate{
        id:id_menudelegate        
        m_icon: sourceIcon
        m_name: name
        m_id: idMenu
        Component.onCompleted: {
            id_menudelegate.clicked.connect(rowClicked)

        }

    }

    // co the set lai listmode
    property SourceListModel m_model: ApplicationInfo.sourceInfos


    //slots
    function addMenuDelegate(_id, _sourceicon , _name){
        var size = m_model.count;
        if(size === 0){
            m_model.append(    {"idMenu":_id ,"sourceIcon" : _sourceicon, "name" :_name}             );
        }else
        {
            m_model.insert(size -1 , {"idMenu":_id , "sourceIcon" : _sourceicon, "name" :_name}  );
        }
    }

    function rowClicked(id, index)
    {
        console.log("row Clicked", index);

        console.log("size model ", m_model.count);
        if(index === m_model.count - 1){
            //addMenuDelegate(id, "<img src=\"http://static.me.zing.vn/v3/zrcmd/nr2_sources_images/ldpi/news.zing.vn.png\" />","bao moi")
        } else{
            ApplicationInfo.changeSource(id);
            id_mainwindow.getArticleCategoryRequestFromSource(id)
            id_mainwindow.state = id_mainwindow._STATE_SHOWMAINVIEW
            //id_mainview.clearDataModelCategory();
        }
    }

    // list cac men nuu
    ListView {
        id: id_listMenu
        anchors.fill: parent
        //anchors.top: parent.top
        // anchors.bottom: parent.bottom;
        //height: parent.height
        //mode: m_model
        model: m_model
        spacing: 3 * m_ratio
        delegate: m_menuDelegate
        highlight: Rectangle { color: "steelblue" }
        highlightMoveVelocity: 9999999
    }
}
